<?php
class cls_data_productdetail extends cls_data_base
{		
	function get_product_info($product_id)       /*杈撳叆浜у搧id锛�杈撳嚭product琛ㄩ噷鐨勫叧浜庤浜у搧鐨勬墍鏈変俊鎭�*/
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select p.*,ps.Quantity,pm.productcomment
			  from product p 
			  	left join productstatistic ps on p.ID=ps.productID
			  	left join productcomment pm on p.ID=pm.productID
		      where p.ID='{$product_id}'";
		$product_detail=$this->db->getrow($sql);
		return $product_detail;
	}
		
	function get_favorites($user_name,$product_id)  /*杈撳叆鐢ㄦ埛鍚嶅拰浜у搧id锛�鏈夋敹钘忔椂杩斿洖1锛�鏃犳敹钘忚繑鍥�0 */
	{
		$product_id=mysql_escape_string($product_id);
		$user_name=mysql_escape_string($user_name);
		$sql="select * from 
			  favorites f,customer c 
			  where f.productid='{$product_id}' and c.id ='{$user_name}' and c.id =f.customerid";
		$favorites=$this->db->getrow($sql);

		return $favorites;		
	}
	
	function get_product_discount($product_id)
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select d.* from 
			  discountproduct dp,discount d 
			  where d.ID = dp.DiscountID and dp.productid='{$product_id}'";
		$product_discount=$this->db->getrow($sql);
		return $product_discount;
	}
	
	function set_favorites($user_name,$product_id)
	{		
		$product_id=mysql_escape_string($product_id);
		$user_name=mysql_escape_string($user_name);
		$sql="insert into favorites(customerid,productid) values('{$user_name}','{$product_id}')";
		$this->db->query($sql);

	}
	
	

}